﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using SimpleOrmCFPC.Core.Query.Requests;
using SimpleOrmCFPC.Core.Query.expressions.RequestBuilder.WhereElmentsBuilder.Helpers;

namespace SimpleOrmCFPC.Core.Query.expressions.ExprssionCompilers.Helpers
{
    public class CastWhereElementFromExpressionComputer : IWhereElementBuilder
    {
        private AnyWhereElementFromExpressionComputer anyWhereElementComputer;

        public CastWhereElementFromExpressionComputer(AnyWhereElementFromExpressionComputer anyWhereElementComputer)
        {
            this.anyWhereElementComputer = anyWhereElementComputer;
        }

        public IWhereElement Compute(Expression expression)
        {
            var u = (UnaryExpression)expression;
            var valr = anyWhereElementComputer.Compute(u.Operand);
            return new CastWhereElement(u.Type, valr);
        }

        public void FillAdditionalInformation(Expression expression, SQLRequest request)
        {
            var u = (UnaryExpression)expression;
            anyWhereElementComputer.FillAdditionalInformation(u.Operand, request);
        }
    }
}
